package com.csdj.controller;


import com.csdj.exception.ServiceException;
import com.csdj.exception.UsernameDuplicateException;
import com.csdj.pojo.TUser;
import com.csdj.service.ITUserService;
import com.csdj.utils.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 今晚几点睡Ada
 * @since 2022-09-07
 */
@RestController
@RequestMapping("/user")
@Api(tags = "用户controller")
public class TUserController extends BaseController {

    @Autowired
    private ITUserService userService;


    @PostMapping("/addUser")
    public JsonResult<Void> addUser(TUser user){
        userService.addUser(user);
        return new JsonResult<Void>(ok);
    }
    @PostMapping("/toLogin")
    public JsonResult<TUser> toLogin(TUser user, Boolean auto, HttpSession session, Model model){
        TUser LoginUser = userService.toLogin(user);
        //登录成功存入session
        session.setAttribute("LoginUser",LoginUser);
        return new JsonResult<>(ok,LoginUser);
    }

}

